package com.example.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.reggie.entity.Orders;
import com.example.reggie.entity.ShoppingCart;
import com.example.reggie.service.OrdersService;
import com.example.reggie.service.ShoppingCartService;
import com.example.reggie.utils.BaseContext;
import com.example.reggie.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/order")
@Slf4j
public class OrdersController {


    @Autowired
    private OrdersService ordersService;

    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders){
        ordersService.submit(orders);
        return R.success("下单成功");
    }

    @GetMapping("/userPage")
    public R userPage(int page,int pageSize){
        LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Orders::getUserId,BaseContext.getId());
        IPage iPage = new Page(page,pageSize);
        ordersService.page(iPage,lqw);
        return R.success(iPage);
    }
    @GetMapping("/page")
    public R page(int page,int pageSize){
        LambdaQueryWrapper<Orders> lqw = new LambdaQueryWrapper<>();
        IPage iPage = new Page(page,pageSize);
        ordersService.page(iPage,lqw);
        return R.success(iPage);
    }
}
